//
//  SAXTableViewCell.m
//  UI19_XML数据解析作业
//
//  Created by dllo on 16/4/5.
//  Copyright © 2016年 付冬梅. All rights reserved.
//

#import "SAXTableViewCell.h"
#import "CartoonModel.h"
#import "UIImageView+WebCache.h"

@interface SAXTableViewCell ()

@property (nonatomic, retain) UILabel *nameLabel;
@property (nonatomic, retain) UILabel *descLabel;
@property (nonatomic, retain) UIImageView *picView;

@end
@implementation SAXTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createTableViewCell];
    }
    return self;
}

- (void)createTableViewCell {
    self.nameLabel = [[UILabel alloc] init];
    [self.contentView addSubview:self.nameLabel];
    self.picView = [[UIImageView alloc] init];
    [self.contentView addSubview:self.picView];
    self.descLabel = [[UILabel alloc] init];
    [self.contentView addSubview:self.descLabel];
    
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    self.nameLabel.frame = CGRectMake(10, 10, self.contentView.frame.size.width - 20, 20);
    self.picView.frame = CGRectMake(10, 40, self.contentView.frame.size.width - 20, 200);
    self.descLabel.frame = CGRectMake(10, 250, self.contentView.frame.size.width - 20, self.contentView.frame.size.height - 260);
}

- (void)setCartoonModel:(CartoonModel *)model {
    
    self.nameLabel.text = model.name;
    self.nameLabel.backgroundColor = [UIColor purpleColor];
    self.descLabel.text = model.desc;
    self.descLabel.numberOfLines = 0;
    self.descLabel.backgroundColor = [UIColor purpleColor];
    [self.picView sd_setImageWithURL:[NSURL URLWithString:model.picUrl]];
}

+ (CGFloat)heightOfCellWithText:(NSString *)text {
    SAXTableViewCell *content = [[SAXTableViewCell alloc] init];
    CGRect rect = [text boundingRectWithSize:CGSizeMake(content.frame.size.width - 20, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:17], NSForegroundColorAttributeName:[UIColor grayColor]} context:nil];
    NSLog(@"0000000000000000000000000000%f", rect.size.height);
    return rect.size.height + 260;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
